﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Homework9
{
    public partial class Form1 : Form
    {
        dB db = new dB();
        MySqlDataReader MSDReader = null;
        public Form1()
        {
            InitializeComponent();
            MySqlDataReader MSDReader = db.MSDR("select* from words");
            label3.Text = MSDReader.GetString(0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MSDReader.Read();
            label3.Text = MSDReader.GetString(0);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (MSDReader.GetString(1) == textBox1.Text)
                {
                    label2.Text = "正确";
                }
                else
                    label2.Text = "错误";
            }
        }

    }
    class dB
    {
        public MySqlConnection Getconnection()
        {
            string conStr = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\ASUS\source\repos\Homework9\Database1.mdf; Integrated Security = True";
            MySqlConnection MS = new MySqlConnection(conStr);
            MS.Open();
            return MS;
        }
        public MySqlDataReader MSDR(string comm)
        {
            MySqlConnection MS = Getconnection();
            MySqlCommand MSCmd = new MySqlCommand(comm, MS);
            MySqlDataReader MSDReader = MSCmd.ExecuteReader();
            return MSDReader;
        }

    }
}
